<script>
import {defineComponent} from 'vue'
import {getTicketList} from "@/api/api";

export default defineComponent({
    name: "selectEvent",
    data() {
        return {
            localselectEvent:false,
            currentEvent:undefined,
            ticketList:[
            ],
            current:null
        }
    },
    methods:{
        close(){
            this.$emit('DialogClose')
        },
        ok(){
            if (!this.currentEvent){
                this.$message.error('请选择一个操作任务')
                return
            }
            this.close()
          this.current=this.ticketList.find(item=>item.id===this.currentEvent)
             this.$emit('selectEvent',this.current)
        },
        async initTicketList(){
            const params={
                type:this.title==='调用典型票'?'典型票':this.title==='专家库开票'?'专家票':"",
            }
            const res=await getTicketList(params)
            if (res.data.code===200){
                if (res.data.data.length===0){
                    this.$message.error('当前暂无操作票数据')
                    return
                }
                this.ticketList=res.data.data
            }else{
                this.$message.error('获取操作票列表失败，请检查网络设置')
            }
        },
    },
    props:{
        selectEvent:{
            type:Boolean,
            default:false
        },
        title:{
            type:String,
            default:''
        }
    },
    watch: {
        selectEvent(newVal) {
            this.localselectEvent = newVal;
            this.currentEvent=undefined
            if (newVal){
                this.initTicketList();
            }

        }
    },
})
</script>

<template>
    <el-dialog :title="title"   :close-on-click-modal="false" :modal="false"
               :close-on-press-escape="false"  :visible.sync="localselectEvent" width="30rem" @close="close" custom-class="switchPatrolDialog" >
      <span style="color: #fff;margin-top: 2rem">请选择一个操作任务</span>
        <el-select v-model="currentEvent"  style="height: 5rem;margin-top: 1rem">
            <el-option v-for="item in ticketList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <div class="btns" style="margin-bottom: 1rem;text-align: center">
            <el-button @click="close" style="margin-left: auto" size="mini">取消</el-button>
            <el-button  @click="ok" size="mini">确定</el-button>
        </div>

    </el-dialog>
</template>

<style scoped lang="less">
.el-button{
  color: #ebeff0;
  background: linear-gradient(#176575,#07283f);
  border:0;
  box-shadow: 0 -2px 0 rgba(16, 164, 195, .8);
  width: 8rem;
}


.btns{
  margin-top: 1rem;
}
</style>
